package zozopo.oa;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.operations.oa.AddressbookOS;
import zozopo.operations.oa.AddressbookTB;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreModifyAddressbookAction extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String limitedCode ="OA.ADDRESSBOOK.MODIFY";
	
	private AddressbookTB addressbook;
	private Integer id;
	
	private Map<Object, Object> session;
	
	public String execute(){
		
		UserTB user = (UserTB)session.get("userInfo"); 
		
		if(user == null){
			addFieldError("errormessage", "用户未登陆或超时.请登陆后操作.");
			return NONE;
		}
		
		Character limitflag64 = user.getUser_limitflag().charAt(64);
		Integer intLimitflag64 = Integer.parseInt(limitflag64.toString());
		
		//System.out.println(limitflag);
		
		if(intLimitflag64 < 1){
			addFieldError("errormessage", "没有管理OA系权限");
			return NONE;
		}
		
		AddressbookOS addressbookOS = new AddressbookOS();
		addressbook = addressbookOS.getAddressbookById(id);
		addressbookOS.releaseConnection();
		return SUCCESS;
	}
	
	public void validate() {
		//权限处理
		UserTB user = (UserTB) session.get("userInfo");
		
		if(user == null){
			addFieldError("errormessage",getText("user.timeoutornotlogin"));
			return ;
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> userlimitedMap = (Map<String,OperatorlimitedTB>)session.get("userlimitedMap");
		
		if(userlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户没有修改通迅录权限.");
			return;
		}
		
		
	}
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	public AddressbookTB getAddressbook() {
		return addressbook;
	}

	public void setAddressbook(AddressbookTB addressbook) {
		this.addressbook = addressbook;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}


}
